<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" 
      xmlns:sec="http://www.pollix.at/thymeleaf/shiro">
<head th:replace="admin/common/html/tableHead :: tableHead(~{::title},~{::link},~{::style})">

<title th:text=${title}></title>
<!-- 这儿引用单独的css link -->
<!-- Ladda for Bootstrap 3按钮加载进度插件 -->
<link rel="stylesheet" th:href="@{/static/admin/assets/js/button/ladda/ladda.min.css}">
<!-- bootstrap-table表单样式 -->
<link th:href="@{/static/admin/assets/js/bootstrap/css/bootstrap-table/bootstrap-table.min.css}" rel="stylesheet"/>

	<!-- 文件上传css-->
	<link th:href="@{/static/admin/assets/js/dropZone/downloads/css/dropzone.css}" rel="stylesheet"/>
<style type="text/css">

	body {
		color: #9ea7b3;
		font-family: "Open Sans", Arial, sans-serif!important;
		font-size: 13px!important;
		line-height: 20px;
		overflow-x: hidden!important;
		min-height: 100%;
		z-index: -2;
		margin: 0px !important;
		background-image: none;
		-moz-background-size: cover;
		-webkit-background-size: cover;
		-o-background-size: cover;
		background-size: cover;
	}
	label.error {
		position: absolute;
		right: 18px;
		top: 5px;
		color: #ef392b;
		font-size: 12px;
	}

</style>

</head>

<body>
      	   	      	      
<div class="content-wrap">
	<div class="row">
		<div class="col-sm-12">
			<div class="nest" id="elementClose">
				<div class="">
				</div>
				<div class="body-nest" id="element">
					<div class="panel-body">
						<form  class="form-horizontal m" id="form-edit" th:object="${HhbFile}">
							<input id="id" name="id" type="hidden" th:field="*{id}"/>
							<div class="form-group">
								<!-- 验证用 -->
								<input class="form-control" type="hidden" id="checkname" th:value="*{fileName}"/>

								<label class="col-sm-3 control-label ">文件名：</label>
								<div class="col-sm-8">
									<input class="form-control" type="text" id="fileName" name="fileName" th:value="*{fileName}"/>
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label ">状态：</label>
								<div class="col-sm-8">
									<select id="status" name="status"   class="form-control valid" aria-invalid="false">
										<option value="0" selected="selected">停用</option>
										<option value="1">启用</option>
									</select>
								</div>
							</div>

							<div class="form-group">
								<label class="col-sm-3 control-label "></label>
								<div class="col-sm-8">
									<input type="hidden" id="dataId" name="dataId">
									<div id="dropz"  class="dropzone"></div>
								</div>
							</div>

			
									<div class="form-group">
										<div class="form-control-static col-sm-offset-9">
											<button type="submit" class="btn btn-primary">提交</button>
											<button onclick="$.modal.close()" class="btn btn-danger" type="button">关闭</button>
										</div>
									</div>
						</form>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>

<!-- 通用js -->
<div th:include="admin/common/html/js :: onload_js">
   
</div>
<!-- bootstarp 表格 -->
<script th:src="@{/static/admin/assets/js/bootstrap/js/bootstrap-table/bootstrap-table.min.js}" type="text/javascript"></script>
<script th:src="@{/static/admin/assets/js/bootstrap/js/bootstrap-table/locale/bootstrap-table-zh-CN.min.js}" type="text/javascript"></script>
<script th:src="@{/static/admin/assets/js/bootstrap/js/base_list.js}" type="text/javascript"></script>


<!-- 弹窗 -->
<script th:src="@{/static/admin/assets/js/layer/layer.js}" type="text/javascript"></script>
<!-- 遮罩层 -->
<script th:src="@{/static/admin/assets/js/blockUI/jquery.blockUI.js}" type="text/javascript"></script>
<script type="text/javascript">
$(function(){
	//文件上传
	Dropzone.autoDiscover = false;//防止报"Dropzone already attached."的错误
	var myDropzone = new Dropzone("#dropz", {
		url: "/FileController/upload",//文件提交地址
		method:"post",  //也可用put
		paramName:"file", //默认为file
		maxFiles:1,//一次性上传的文件数量上限
		maxFilesize: 2, //文件大小，单位：MB
		acceptedFiles: ".pdf", //上传的类型
		addRemoveLinks:true,
		parallelUploads: 1,//一次上传的文件数量
		//previewsContainer:"#preview",//上传图片的预览窗口
		dictDefaultMessage:'拖动文件至此或者点击上传',
		dictMaxFilesExceeded: "您最多只能上传1个文件！",
		dictResponseError: '文件上传失败!',
		dictInvalidFileType: "文件类型只能是*.pdf",
		dictFallbackMessage:"浏览器不受支持",
		dictFileTooBig:"文件过大上传文件最大支持.",
		dictRemoveLinks: "删除",
		dictCancelUpload: "取消",
		init:function(){
			this.on("addedfile", function(file) {
				//上传文件时触发的事件

			});
			this.on("success",function(file,data){
				//上传成功触发的事件
				if(data!=null&&data!=""){
					$("#dataId").val(data.data);
				}else if (data.code==500) {
					$.modal.alertError(data.msg);
					myDropzone.removeFile(file);
				}else{
					$.modal.alertError("文件为上传失败！");
					myDropzone.removeFile(file);
				}

			});
			this.on("error",function (file,data) {
				//上传失败触发的事件
				$.modal.alertError(data);
			});
			this.on("removedfile",function(file){//删除文件触发结果
				//console.log(file);
				$.ajax({
					url:window.rootPath+"/FileController/del_file",
					type:"post",
					data:{"ids":$("#dataId").val()},
					success:function(data){
						$("#dataId").val("");
					}
				})
				$("#dataId").val("");
			});
		}
	});
})



$("#form-edit").validate({
	rules:{
		name:{
			required:true,
			minlength: 2,
			maxlength: 20,
			remote: {
				url: rootPath + "/HhbFileController/checkNameUnique",
				type: "post",
				dataType: "json",
				dataFilter: function(data, type) {
					if (data == "0")
						return true;
					else
						return false;
				}
			}
		}
	},
	messages: {
		"name": {
			remote: "文件名已经存在"
		}
	},
	submitHandler:function(form){
		edit();
	}
});


function edit() {
	var dataFormJson = $("#form-edit").serialize();
	$.ajax({
		cache : true,
		type : "POST",
		url : rootPath + "/HhbFileController/edit",
		data : dataFormJson,
		async : false,
		error : function(request) {
			$.modal.alertError("系统错误");
		},
		success : function(data) {
			$.operate.saveSuccess(data);
		}
	});
}
</script>

</body>


</html>
